package com.xiaoyu.awakening.ai.search.controller;

import com.xiaoyu.awakening.ai.search.api.IAwkSearchControllerApi;
import com.xiaoyu.awakening.ai.search.context.AwkSearchContext;
import com.xiaoyu.awakening.ai.search.model.AwkSearchContent;
import com.xiaoyu.awakening.ai.search.model.dto.SearchResultDTO;
import com.xiaoyu.awakening.ai.search.model.vo.SearchRequestVO;
import com.xiaoyu.awakening.ai.search.service.IAwkSearchService;
import com.xiaoyu.awakening.common.core.dto.Result;
import org.springframework.web.bind.annotation.RestController;

/**
 * 检索接口
 *
 * @author wangxiaoyu
 * @date 2025/8/5 14:51
 * @since v1.0
 */
@RestController
public class AwkSearchController implements IAwkSearchControllerApi {
    private final IAwkSearchService awkSearchService;

    public AwkSearchController(IAwkSearchService awkSearchService) {
        this.awkSearchService = awkSearchService;
    }

    @Override
    public Result<SearchResultDTO<AwkSearchContent>> search(SearchRequestVO searchRequestVo) {
        AwkSearchContext<AwkSearchContent> context = initSearchContext(searchRequestVo);
        SearchResultDTO<AwkSearchContent> searchResultDTO = awkSearchService.search(context);
        return Result.success(searchResultDTO);
    }

    private AwkSearchContext<AwkSearchContent> initSearchContext(SearchRequestVO searchRequestVo) {
        return new AwkSearchContext<>(searchRequestVo);
    }
}
